package main

import "fmt"

func main() {
	// 创建切片
	numbers := []int{0, 1, 2, 3, 4, 5, 6, 7, 8}
	printSlice(numbers)
	// 打印原始切片
	fmt.Println("numbers = ", numbers)
	// 打印子切片从索引1到索引4
	fmt.Println("numbers[1:4] = ", numbers[1:4])
	// 默认下限为0
	fmt.Println("numbers[:3] = ", numbers[:3])
	// 默认上限为 len(s)
	fmt.Println("numbers[4:] = ", numbers[4:])
	// 打印切片从索引0到索引2
	number2 := numbers[:2]
	printSlice(number2)
	// 打印切片从索引2到索引5
	number3 := numbers[2:5]
	printSlice(number3)
}

func printSlice(x []int) {
	fmt.Printf("len=%d, cap=%d, slice=%v\n", len(x), cap(x), x)
}
